<template>
	<el-card class="form-container" style="width: 80%;">
		<el-form :model="dataForm" ref="dataForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="90px">
			<el-row>
				<el-col :span="12">
					<el-form-item label="模块名称" prop="moduleName">
						<el-select v-model="dataForm.moduleName" class="input-width" placeholder="全部" clearable style="width:85%">
							<el-option v-for="item in moduleList"
								:key="item.id"
								:label="item.moduleName"
								:value="item.moduleName">
							</el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="是否发布" prop="sendStatus">
						<el-radio-group v-model="dataForm.sendStatus">
							<el-radio :label="1">是</el-radio>
							<el-radio :label="2">否</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="消息标题" prop="messageTitle">
				<el-input v-model="dataForm.messageTitle" placeholder="请输入消息标题"></el-input>
			</el-form-item>
			<el-form-item label="链接地址" prop="messageLink">
				<el-input v-model="dataForm.messageLink" placeholder="请输入链接地址"></el-input>
			</el-form-item>
			<el-form-item label="消息内容" prop="messageContent">
					<Editor 
						v-model="dataForm.messageContent" 
						:acceptType="uploadSetting.uploadAcceptType"
						:uploadType="uploadSetting.uploadType" 
					/>
			</el-form-item>
			<!-- <template v-if="dataForm.sendStatus == 1">
				<el-form-item label="发送类型" prop="sendType">
					<el-radio-group v-model="dataForm.sendType" size="small" @change="handlerChange">
						<el-radio-button :label="1">全员发送</el-radio-button>
						<el-radio-button :label="2">指定人员</el-radio-button>
					</el-radio-group>
				</el-form-item>
				根据当前消息版块查询出接收此消息版块的用户信息
				<template v-if="dataForm.sendType == 2">
					
				</template>
			</template> -->
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="submit('dataForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import { addMessageText ,findMessageModuleList} from '@/api/platform/message'
	import Editor from '@/components/editor';
	export default {
		name: 'add-messageText',
		data() {
			return {
				dataForm: {
					messageTitle: '',
					messageContent: '',
					sendType: 1,
					moduleName: '',
					messageLink: '',
					sendStatus: 1,
				},
				dataRule: {
					messageTitle: [{
							required: true,
							message: '请输入消息标题',
							trigger: 'blur'
						},
					],
					messageContent: [{
							required: true,
							message: '请输入消息内容',
							trigger: 'blur'
						},
					],
					sendType: [{
							required: true,
							message: '请输入发送类型',
							trigger: 'blur'
						},
					],
					moduleName: [{
							required: true,
							message: '请选择模块名称',
							trigger: 'blur'
						},
					],
					messageLink: [{
							required: true,
							message: '请输入链接地址',
							trigger: 'blur'
						},
					]
				},
				moduleList:[],
				uploadSetting:{
					uploadType:'eyeglass-user',
					uploadAcceptType:['image/jpeg','image/jpg','image/png'],
				},
			}
		},
		created() {
			this.initMessageModule()
		},
		components:{
			Editor
		},
		methods: {
			initMessageModule(){
				let params ={
					isShow: 1
				}
				findMessageModuleList(params).then(res =>{
					if(res.data.responseCode == 200){
						this.moduleList = res.data.responseData
					}
				})
			},
			cancel() {
				this.$router.go(-1)
			},
			submit() {
				const set = this.$refs;
				set['dataForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					addMessageText(this.dataForm).then(() => {
						this.$notify({
							title: '添加成功',
							message: '添加成功',
							type: 'success',
							duration: 2000,
							onClose: this.$router.go(-1)
						})
					})
				})
			},
			handlerChange(val){
				console.log(val)
			}
		}
	}
</script>

<style>
</style>
